<template>
  <table class="order-table">
    <thead>
      <tr>
        <th>影片</th>
        <th>时间</th>
        <th>演出厅</th>
        <th>座位</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="movie-name">《{{ tableData[0].movieName }}》</td>
        <td class="showtime">
          {{ getTime(tableData[0].Time) }} {{ tableData[0].Time | fmtTime() }}
        </td>
        <td class="cinema-name">{{ tableData[0].address }}</td>
        <td>
          <div class="seats">
            <div>
              <span
                :class="index > 0 ? 'border' : ''"
                v-for="(seat, index) in selectedSeat"
                :key="seat.id"
                ><i>{{ seat.row }}</i
                >排<i>{{ seat.col }}</i
                >座</span
              >
            </div>
            <div></div>
          </div>
        </td>
      </tr>
    </tbody>
  </table>
</template>

<script>
import { getWeekDate } from '@/utils/index.js'
import dayjs from 'dayjs'
export default {
  name: 'TtmsList',

  data () {
    return {}
  },

  mounted () {},

  methods: {
    getTime (date) {
      const day = dayjs(dayjs(date).format('YYYY-MM-DD')).diff(
        dayjs(new Date()).format('YYYY-MM-DD'),
        'day'
      )
      if (day === 0) {
        return '今天'
      } else if (day === 1) {
        return '明天'
      } else if (day === 2) {
        return '后天'
      } else {
        return getWeekDate(day)
      }
    }
  },
  props: ['selectedSeat', 'plan', 'order'],
  computed: {
    tableData () {
      if (this.plan) {
        return [
          {
            movieName: this.plan.mName,
            Time: this.plan.pStarttime,
            address: this.plan.hName,
            selectedSeat: this.selectedSeat
          }
        ]
      } else {
        return [
          {
            movieName: this.order.mName,
            Time: this.order.startDate,
            address: this.order.hName
          }
        ]
      }
    }
  },
  filters: {
    fmtTime (value, format = 'MM月DD HH:mm') {
      return dayjs(value).format(format)
    }
  }
}
</script>

<style lang="scss" scoped>
.order-table {
  width: 100%;
  border: 1px solid #e5e5e5;
  border-spacing: 0;
  margin-bottom: 60px;
}
.order-table thead {
  background-color: #f7f7f7;
}
.order-table thead th {
  font-size: 16px;
  color: #333;
  width: 25%;
  padding: 14px 0;
  font-weight: 400;
}
.order-table .movie-name {
  font-size: 16px;
}

.order-table td {
  text-align: center;
  padding: 20px 0;
  color: #333;
}
.order-table .showtime {
  font-size: 14px;
  color: #f03d37;
}
.order-table .cinema-name {
  font-size: 14px;
}
.order-table .seats {
  display: inline-block;
  text-align: left;
}
.order-table .seats span {
  font-size: 12px;
  margin-right: 2px;
}
.order-table .seats i {
  font-size: 16px;
  font-style: normal;
  margin: 0 2px;
}
.order-table .seats span.border {
  border-left: 1px solid #e5e5e5;
  padding-left: 5px;
}
</style>
